From 62184014dfd969fa2c23d234e89951e088d7e6ec Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Thu, 14 Dec 2006 10:31:31 +0000 Subject: [PATCH] Set FD_CLOEXEC on the pidfile fd, so that tapdisk does not get it. Signed-off-by: Ewan Mellor --- tools/blktap/drivers/blktapctrl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/blktap/drivers/blktapctrl.c b/tools/blktap/drivers/blktapctrl.c index b16ab516b5..f2022fcc97 100644 --- a/tools/blktap/drivers/blktapctrl.c +++ b/tools/blktap/drivers/blktapctrl.c @@ -629,6 +629,7 @@ static void write_pidfile(long pid) char buf[100]; int len; int fd; + int flags; fd = open(PIDFILE, O_RDWR | O_CREAT, 0600); if (fd == -1) { @@ -640,6 +641,18 @@ static void write_pidfile(long pid) if (lockf(fd, F_TLOCK, 0) == -1) exit(0); + /* Set FD_CLOEXEC, so that tapdisk doesn't get this file + descriptor. */ + if ((flags = fcntl(fd, F_GETFD)) == -1) { + DPRINTF("F_GETFD failed (%d)\n", errno); + exit(1); + } + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) { + DPRINTF("F_SETFD failed (%d)\n", errno); + exit(1); + } + len = sprintf(buf, "%ld\n", pid); if (write(fd, buf, len) != len) { DPRINTF("Writing pid file failed (%d)\n", errno); -- 2.30.2